-- =======================
-- =Crate SENT by Mahalis
-- =======================

AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

function ENT:Initialize()
	self:SetModel("models/props/cs_office/radio.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	self.damage = 100
	local ply = self:GetNWEntity("owning_ent")
	self.Entity.SID = ply.SID
	self.SID = ply.SID
	self.Entity.CanUse = true
	self:SetNetworkedString("Owner", ply:Nick())
	self:SetNetworkedString("station", '"http://specific.dk/listen.wvx"')
end

function ENT:OnTakeDamage(dmg)
	self.damage = self.damage - dmg:GetDamage()
	if (self.damage <= 0) then
		self:Remove()
	end
end

function ENT:Destruct()
end

function ENT:Use(activator,caller)
	if not self.Entity.CanUse then return false end
	self.Entity.CanUse = false
	timer.Simple(0.5, function() self.Entity.CanUse = true end)
	if not activator:GetNWInt("RadioL") then activator:SetNWInt("RadioL", 0) end
	activator:ConCommand("radiomenu")
/*
	if not self:GetNWString("station") or self:GetNWString("station") == "" then self:SetNWString("station", '"http://specific.dk/listen.wvx"') end
	self.drug_user = activator
	if not activator:GetNWInt("RadioL") then activator:SetNWInt("RadioL", 0) end
	if activator:GetNWInt("RadioL") == 0 then
		activator:ConCommand("+RPRadio " .. tostring(self:GetNWString("station")))
		activator:SetNWInt("RadioL", 1)
	else
		activator:ConCommand("-RPRadio")
		activator:SetNWInt("RadioL", 0)
	end
	*/
end

function ENT:Think()
	if not self.SID then 
		self.SID = self:GetNWEntity("owning_ent")
	end
end

function ENT:OnRemove()
	self:Destruct()
end